package com.lyy.photovoltaic.controller;

import com.lyy.photovoltaic.common.vo.ResultVO;
import com.lyy.photovoltaic.service.AdministratorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/admin")
@Api(value = "管理员登录接口", tags = "管理员登录")
public class AdministratorController {
    @Autowired
    AdministratorService administratorService;

    @ApiOperation(value = "管理员登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "aid", value = "管理员登录账号", required = true),
            @ApiImplicitParam(dataType = "string", name = "pwd", value = "管理员登录密码", required = true)
    })
    @PostMapping("/login")
    public ResultVO login(@RequestParam("aid") String aId, @RequestParam("pwd") String pwd) {
        ResultVO resultVO = administratorService.checkLogin(aId, pwd);
        return resultVO;
    }

    @PostMapping("/regist")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "aid", value = "用户注册账号", required = true),
            @ApiImplicitParam(dataType = "string", name = "pwd", value = "用户注册密码", required = true)
    })
    @ApiOperation(value = "管理员注册接口")
    public ResultVO register(@RequestParam("aid") String aId, @RequestParam("pwd") String pwd) {
        ResultVO resultVO = administratorService.adminRegist(aId,pwd);
        return resultVO;
    }
}

